<?php
// 本类由系统自动生成，仅供测试用途
class QkAction extends Action {

	
	//预设  para一般自身的所有以及扩展的zabojingua东西
	//聚合
    private $all=array(
    	'mdmk'=>'Qk',//NB
  		'ttl'=>'贵鼎物流',
  		'jn'=>array(),//NB
      //自己的全部+f的显示的东西
  		'para'=>array('qkid'=>'qkID','qkdate'=>'日期','qkshopnm'=>'店铺名称','qktuoyunno'=>'快递单号','qkcustomernm'=>'收货人','qkcustomercp'=>'收货电话','qkprovince'=>'省份','qkcargoaddress'=>'收货地址','qkyewubumen'=>'业务部门','qksendmethod'=>'送货方式','qkjianshu'=>'打包件数','qkdetail'=>'发货明细','qkzhongzhuanzhuanxian'=>'专线名称','qkzhongzhuanno'=>'专线单号','qkzhuanxianmethod'=>'专线送货方式','qkmoduandianhua'=>'末端电话','qkpic'=>'图片','qkprocesstm'=>'处理时间','qktrack'=>'物流跟踪','qkprocessresult'=>'处理结果'),//NB
  		//抛去不是zabojin的属性针对para
      'notself'=>array(),
       ##########modify 添加修改中不需要展示和理会的属性 针对para
      'no_update'=>array('qkid','qkshopnm','qkmoduandianhua'),
      #####update的时候允许为空的值 针对zabojin刨掉不然显示的update字段后
      'allowempty'=>array('qkmoduandianhua','qkpic','qkprocesstm','qkprocessresult'),

      'hide_fld'=>array('qkid'),//NB
      'hide_cdt'=>array('qkid','qkshopnm','qkmoduandianhua','qkpic'),//NB
  		
    //   'spccdtls'=>array('spccdt_0'=>array('aaid<>0','aaID不为0【废话只是测试】')),
  		// 'odrls'=>array('aanm'),
    //   'spccdt_dflt'=>array('spccdt_0'),
    //   'odr_dflt'=>array('aanm'=>'ASC'),

      'spccdtls'=>array(),//NB
      'odrls'=>array(),//NB
      'spccdt_dflt'=>array(),//NB
      'odr_dflt'=>array(),//NB
      //hide的fld必须有，他们虽然不显示但是必须选择，这样才能在第一次进入query的时候，隐藏属性可以被调用，特别是id和fid
  		'fld_dflt'=>array('qkid','qkdate','qktuoyunno','qkcustomernm','qkcustomercp','qkprovince','qkcargoaddress','qkyewubumen','qksendmethod','qkjianshu','qkdetail','qkzhongzhuanzhuanxian','qkzhongzhuanno','qkzhuanxianmethod','qkpic','qktrack','qkprocessresult'),//NB
  		'cdt_dflt'=>array(),//NB
  		
  		'lmt_dflt'=>10,//NB
  		
  		'defaultls'=>1,//默认枚举//NB
  		##########view
  		'no_view'=>array('qkid','qkshopnm','qkmoduandianhua'),
	   
      #########删除提醒
      'deleteconfirm'=>'确定要删除此条记录？',
      #####转义
      // 'transmean'=>array('qksendmethod'=>array('0'=>'自提','1'=>'送货上门'),'qkprocessresult'=>array('0'=>'配送中','1'=>'已签收','2'=>'配送失败')),//NB
      // 'transmean'=>array('qksendmethod'=>array('0'=>'自提','1'=>'送货上门')),//NB
      'transmean'=>array(),//NB
      #####默认值
      'dfltvalue'=>array('qksendmethod'=>0),
      ########新增属性
      'linkage'=>array(),//如果ccc的变换需要转换成2015_ccc 就是2  否则如果是1 非2情况下联动没有值，不允许下拉，3联动不造成下拉有无
      ########这里是谁影响谁，用在AJAX联动 效果极佳
      'impactfactor'=>array(),
      
    );

    //公版
    public function query(){
    	header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');
      $pb->query($this->all);

      // $arr_mls=$pb->query($this->all);$mls=$arr_mls['data'];

      // $mlsnw=array();
      // foreach($mls as $mv){
      //   if($mv['zsxmwa']){
      //     // $strPreg = '/<img src="([\s\S]*?)"\/>/';
      //     preg_match('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$mv['zsxmwa'],$match);
      //     $img=$match[0];
      //     if($img){
      //       $img=str_replace('<img', "<img style='height:80px;width:80px' ", $img);
      //       $mv['zsxmwa']=$img;
      //     }else{
      //       $mv['zsxmwa']=substr($mv['zsxmwa'], 0,20).'...';
      //     }
          
      //   }

        
      //   if($mv['zsxmyhq']){$mv['zsxmyhq']="<a href='".$mv['zsxmyhq']."' target='_blank'>".substr($mv['zsxmyhq'], 0,10).'...'."</a>";}
      //   if($mv['zsxmlink']){$mv['zsxmlink']="<a href='".$mv['zsxmlink']."' target='_blank'>".substr($mv['zsxmlink'], 0,10).'...'."</a>";}
      //   array_push($mlsnw,$mv);
      // }
      // $this->assign('mls',$mlsnw);


      $this->display('query');
  
    }

    public function export(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');$xls=D('Xls');

      $arr_return=$pb->queryALL($this->all);$return=$arr_return['data'];
      $thls=$return['thls'];$mls=$return['mls'];

      foreach($thls as $thvk=>$thvv){
        if($thvv=='图片'){unset($thls[$thvk]);}
      }

      $mlsnw=array();
      foreach($mls as $mv){
        unset($mv['qkid']);
        unset($mv['qkpic']);
        array_push($mlsnw,$mv);
      }
      
      $xls->export($thls,$mlsnw,'物流数据');
      


    }
    
    //公版
    public function view(){
    	header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');
    	$pb->view($this->all);
		  $this->display('view');
    }
   
   	//公版
   	public function update(){
   		header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');
      $all=$this->all;
      if(gp()['id']==0){$all['dfltvalue']['qkdate']=date('Y-m-d',time());}
      $arr_mo=$pb->update($all);$mo=$arr_mo['data'];
      $mo['qkprocesstm']=date('Y-m-d H:i:s',time());
      $this->assign('mo',$mo);

      $this->assign('project',C('PROJECT'));

		  $this->display('update');
   	}

   	//公版
   	public function doupdate(){
   		header("Content-Type:text/html; charset=utf-8");
   		$pb=D('PB');
   		$arr_pattern=$pb->doupdate($this->all);
   		$data['pattern']=$arr_pattern['data'];

   		$this->ajaxReturn($data,'json');
   	}

   	//公版
   	public function dodelete(){
   		header("Content-Type:text/html; charset=utf-8");
   		$pb=D('PB');
   		$pb->dodelete($this->all);
  		
   		$this->ajaxReturn($data,'json');
   	}

    //公版
    public function dobatchdelete(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');
      $pb->dobatchdelete($this->all);
      
      $this->ajaxReturn($data,'json');
    }

    //公版
    public function doalldelete(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');
      $pb->doalldelete($this->all);
      
      $this->ajaxReturn($data,'json');
    }

    public function dolinkage(){
      header("Content-Type:text/html; charset=utf-8");
      $nb=D('NB');
      $arr=$nb->dolinkage($this->all);
      
      $data=$arr['data'];
      
      $this->ajaxReturn($data,'json');
    }

    //公版
    public function fenxidaoru(){
      header("Content-Type:text/html; charset=utf-8");
      $qk=D('Qk');
      
      $rslt=1;//默认是正常的
      $tail=session('tail');
      if(!($tail=='xls'||$tail=='xlsx')){
        $rslt=2;//文件格式不正确
      }else{
        //如果格式没问题，就开始读取数据了
        import('@.ORG.PHPExcel');
        //设定缓存模式为经gzip压缩后存入cache（PHPExcel导入导出及大量数据导入缓存方式的修改 ）
        $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
        $cacheSettings = array();
        PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);
    
        $objPHPExcel = new PHPExcel();
        // $con = mysql_connect("localhost","root","123456");
        // mysql_select_db('bms');
        //读入上传文件
        $myfl=session('myfl');$myfl=str_replace('/'.C('PROJECT'),'.',$myfl);
        //$objPHPExcel = PHPExcel_IOFactory::load($_FILES["inputExcel"]["tmp_name"]);
        $objPHPExcel = PHPExcel_IOFactory::load($myfl);
         
        $currentSheet = $objPHPExcel->getSheet(0);// 当前页
        $row_num = $currentSheet->getHighestRow();// 当前页行数
        $col_max = $currentSheet->getHighestColumn(); // 当前页最大列号

        $arr_error=Array();
        $tongji_success=0;
        $tm=date('Y-m-d H:m:s',time());
        for($i = 2; $i <= $row_num; $i++){
            
            
            $ads = 'A' . $i; // 单元格坐标address
            $qkdate = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'B' . $i; // 单元格坐标address
            $qktuoyunno=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'C' . $i; // 单元格坐标address
            $qkcustomernm=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'D' . $i; // 单元格坐标address
            $qkcustomercp=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'E' . $i; // 单元格坐标address
            $qkprovince=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'F' . $i; // 单元格坐标address
            $qkcargoaddress=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'G' . $i; // 单元格坐标address
            $qkyewubumen=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'H' . $i; // 单元格坐标address
            $qksendmethod=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'I' . $i; // 单元格坐标address
            $qkjianshu=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'J' . $i; // 单元格坐标address
            $qkdetail=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
             $ads = 'K' . $i; // 单元格坐标address
            $qkzhongzhuanzhuanxian=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
             $ads = 'L' . $i; // 单元格坐标address
            $qkzhongzhuanno=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
             $ads = 'M' . $i; // 单元格坐标address
            $qkzhuanxianmethod=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
             $ads = 'N' . $i; // 单元格坐标address
            $qkprocessresult=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
             

            //验证是否重传
            $arr_qko=$qk->getqkoby($qkdate,$qktuoyunno,$qkcustomernm,$qkcustomercp,$qkprovince,$qkcargoaddress,$qkyewubumen,$qksendmethod,$qkjianshu,$qkdetail,$qkzhongzhuanzhuanxian,$qkzhongzhuanno,$qkzhuanxianmethod,$qkprocessresult);$qko=$arr_qko['data'];

            if($qko){
              $rslt=2;
              $dt['xuhao']=$i;
              $dt['qkdate']=$qkdate;
              $dt['qktuoyunno']=$qktuoyunno;
              $dt['qkcustomernm']=$qkcustomernm;
              $dt['qkcustomercp']=$qkcustomercp;
              $dt['qkprovince']=$qkprovince;
              $dt['qkyewubumen']=$qkyewubumen;
              $dt['qkcargoaddress']=$qkcargoaddress;
              $dt['qksendmethod']=$qksendmethod;
              $dt['qkjianshu']=$qkjianshu;
              $dt['qkdetail']=$qkdetail;
              $dt['qkzhongzhuanzhuanxian']=$qkzhongzhuanzhuanxian;
              $dt['qkzhongzhuanno']=$qkzhongzhuanno;
              $dt['qkzhuanxianmethod']=$qkzhuanxianmethod;
              $dt['qkprocessresult']=$qkprocessresult;
              $dt['qkprocesstm']=$tm;
              $dt['beizhu']='此数据已经上传过了';
              array_push($arr_error, $dt);
              continue;
            }

            //都过关了先++，然后把数据搞进去
            $tongji_success++;

            $dt['qkdate']=$qkdate;
            $dt['qktuoyunno']=$qktuoyunno;
            $dt['qkcustomernm']=$qkcustomernm;
            $dt['qkcustomercp']=$qkcustomercp;
            $dt['qkprovince']=$qkprovince;
            $dt['qkyewubumen']=$qkyewubumen;
            $dt['qkcargoaddress']=$qkcargoaddress;
            $dt['qksendmethod']=$qksendmethod;
            $dt['qkjianshu']=$qkjianshu;
            $dt['qkdetail']=$qkdetail;
            $dt['qkzhongzhuanzhuanxian']=$qkzhongzhuanzhuanxian;
            $dt['qkzhongzhuanno']=$qkzhongzhuanno;
            $dt['qkzhuanxianmethod']=$qkzhuanxianmethod;
            $dt['qkprocessresult']=$qkprocessresult;
            $dt['qkprocesstm']=$tm;
            $qk->add($dt);
            
        }
      }

      if($rslt==2){
        $data['arr_error']=$arr_error;
      }
      $data['rslt']=$rslt;
      $data['tongji_success']=$tongji_success;

      $this->ajaxReturn($data,'json');
    }

}